#!/bin/sh -f
# $Id: netsql.sh 3872ff878909 2012/12/02 10:42:35 pgurumur $
# Copyright (c) 2012 Prabhu Gurumurthy <pgurumur@gmail.com>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# __version__  = "$Revision: 3872ff878909 $"
# __author__   = "$Author: pgurumur $"
# __modified__ = "$Date: 2012-12-02 10:42:35Z $"

SQL=`which mysql`
PROG=`basename $0`

function usage {
   echo "${PROG} [ ssn | netdot ] [ ? | help | rw | ro ]"
   echo "Program to login to netdot/manufacturing MySQL database"
   echo
   exit 1
}

if [ $# -eq 0 ]; then
   usage
elif [ $# -eq 2 ]; then
   database=$1
   option=$2

   if [ ${database} = "?" ]; then
      usage
   elif [ ${database} = "ssn" ]; then
      if [ ${option} = "?" ]; then
         usage
      elif [ ${option} = "help" ]; then
         usage
      elif [ ${option} = "rw" ]; then
         logger "logging into manufacturing database with r/w perm"
         ${SQL} -h 10.57.132.160 -D ssn -u netengscript --password="T2buRAwe"
      elif [ ${option} = "ro" ]; then
         logger "logging into manufacturing database with r/o perm"
         ${SQL} -h 10.57.132.160 -D ssn -u netopsscript --password="faWeJu57"
      else
         usage
      fi
   elif [ ${database} = "netdot" ]; then
      if [ ${option} = "?" ]; then
         usage
      elif [ ${option} = "help" ]; then
         usage
      elif [ ${option} = "rw" ]; then
         echo "R/W of netdot thru this script is restricted, contact neteng@"
         exit 1
      elif [ ${option} = "ro" ]; then
         logger "logging into netdot database with r/w perm"
         ${SQL} -h 10.55.84.216 -D netdot -u ops --password="rk807uuN"
      else
         usage
      fi
   else
      usage
   fi
else
   usage
fi
